<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>角色管理</title>
	<link type="text/css" rel="stylesheet" href="../<s:property value="#session.themeStyle.mainCss" default="Skin/PM/cyan/main.css"/>" />
</head>
<body>
	<div class="navBar">
		当前位置：系统管理&nbsp;&gt;&gt;&nbsp;权限管理
	</div>
	<s:form theme="simple">
	<input type="hidden" id="state" value="<s:property value="state"/>" />
	<s:hidden id="rid" name="rid"></s:hidden>
	<div class="tabBlock">
		组织机构：<s:select id="orgId" name="orgId" list="managedOrgList" listKey="orgId" listValue="name" emptyOption="true" onchange="$(\"form\")[0].submit()"></s:select>
		<span> <a href="roleInfo-add.action" class="but28" onclick="return add(this);" style="text-decoration: none;">添加角色</a> &nbsp;&nbsp; </span>
		<div class="dataGrid" style="margin-top: 10px;">
			<table>
				<tr>
					<th style="width:25%;">
						角色名称
					</th>
					<th>
						角色描述
					</th>
					<th style="width:25%;">
						组织机构
					</th>
					<th  style="width:25%;">
						配置功能项
					</th>
				</tr>
				<s:iterator value="result.resultlist" var="role" status="st">
					<tr class="trStyle">
						<td>
							<s:property value="name" />
						</td>
						<td>
							<s:property value="remark" />
						</td>
						<td>
							<s:property value="orgName" />
						</td>
						<td>
							<a href='javascript:void(0)' onclick="return edit(<s:property value="pkId"/>, this)"<s:if test="!mapResult['Edit'][pkId]"> class="disabled"</s:if>>编辑</a>&nbsp;&nbsp;&nbsp;
							<a href='javascript:void(0)' onclick="return del(<s:property value="pkId"/>,'<s:property value="name"/>', this)"<s:if test="!mapResult['Edit'][pkId]"> class="disabled"</s:if>>删除</a> &nbsp;&nbsp;&nbsp;
							<a href='roleInfo-edit.action?rid=<s:property value="pkId"/>&state=<s:property value="state"/>' onclick="return checkRight(this)"<s:if test="!mapResult['UserAuth'][pkId]"> class="disabled"</s:if>>权限配置</a> &nbsp;&nbsp;&nbsp;
							<a href='userRole-manage.action?roleId=<s:property value="pkId"/>&state=<s:property value="state"/>' onclick="return checkRight(this)"<s:if test="!mapResult['UserAuth'][pkId]"> class="disabled"</s:if>>用户授权</a>
						</td>
					</tr>
				</s:iterator>
				<s:if test="result.resultlist.size==0">
					<tr class="trStyle">
						<td colspan="4">
						(空)
						</td>
					</tr>
				</s:if>
			</table>
		</div>
		<div id="actionError" style="display: none;"><s:actionerror/>
		</div>
		<div class="toolbar" style="text-align: center;">
			<a class="but28" onclick="history.back()" style="text-decoration:none;" >返回</a>
			<s:if test="admin">
			<a class="but28" onclick="resetFuncAndRoles()" style="text-decoration:none;" >重置</a>
			</s:if>
		</div>
	</div>
	</s:form>
	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/jquery.leanModal.min.js"></script>
	<script type="text/javascript" src="../js/modalWindow.js"></script>
	<script type="text/javascript" src="../js/RoleFuncManage.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			var errorMessage = $.trim($("#actionError").text());
			if(errorMessage!=''){
				alert(errorMessage);
			}
			$("#actionError").html("");
		});
	
		function add(_this){
			if(haveRight(_this)){
				var state = $("#state").val();
				var orgId = $("#orgId").val();
				var url = "roleInfo-add.action";
				if(orgId!=''){
					url += "?orgId="+orgId;
				}
				$(_this).attr("href", url);
				return true;
			}else{
				alert("没有新建角色权限！")
				return false;
			}
		}
		
		function edit(id,_this) {
			if(haveRight(_this)){
				var form = $("form")[0];
				form.action="roleInfo-edit.action";
				$("#rid").val(id);
				form.submit();
				return true;
			}else{
				alert("没有编辑权限！")
				return false;
			}
			
		}
		
		function del(id, name, _this) {
			var result = haveRight(_this);
			if(haveRight(_this)){
				if (confirm("真的要删除角色["+name+"]吗？")){
					var form = $("form")[0];
					form.action="roleInfo-del.action";
					$("#rid").val(id);
					form.submit();
				}
				return true;
			}else{
				alert("没有删除权限！");
				return false;
			}
		}
		
		//添加用户
		function addUser(){
			var roleId =$("#roleId").val();
			var state = $("#state").val();
			var url = "userRole-userSelect.action?roleId="+roleId;
			showModalWindow(
					url,
					window,
					'resizable:no;scroll:yes;status:no;dialogWidth=300px;dialogHeight=450px;center=yes;help=no',
					function(result){
						if(result!=null&&result!='undefined'&&result!=''){
							var roleId =$("#roleId").val();
						   	var from = createFrom("addUserRole.action");
							loadFrom("roleId",roleId,from);
							loadFrom("userIds",result,from);
							from.submit();
						}
					}
			);
		}
		
	</script>
</body>
</html>